package chatting3.Utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import chatting3.Servers.Message;

public class MsgUtils {

	public  static Message<?> readMsg(InputStream inputStream){
		Message<?> result = null;
		try {
			ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
			result = (Message<?>) objectInputStream.readObject();
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static void writeMsg(OutputStream outputStream,Message<?> message) {
		try {
			ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
			objectOutputStream.writeObject(message);
		}catch (IOException e) {
			e.printStackTrace();
		}
	}
}
